package com.jxw.engine.platsign;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.TextAppearanceSpan;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.jxw.launcher.MyApp;
import com.jxw.launcher.R;
import com.jxw.utils.SystemPropertiesProxy;
import java.io.IOException;
import java.net.SocketException;
import java.util.regex.Pattern;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.json.JSONObject;

/* loaded from: classes.dex */
public class MainActivity extends Activity {
    public static final String APKISBN = "apkIsbn";
    public static final String APKV = "zndzgkptv5";
    public static final String CERTIFICATION = "cert";
    public static final String CUSTOMISBN = "customIsbn";
    public static final int ERROR_ALREADY_REGISTERD = 201;
    public static final int ERROR_OK = 200;
    public static final int ERROR_SERVER_ERROR = 100;
    public static final String PLATFORM = "A89S";
    public static final String PREFERENCE = "preference";
    public static final String REGISTFLAG = "zngbgkptv5";
    public static final String SERIS = "seris";
    private static final String TAG = "zzj";
    private ImageView back;
    boolean is;
    private LinearLayout ll_phone;
    private EditText mInputSeries;
    private Button mRegister;
    private boolean mUseJHTServer = false;
    String mcpuid;
    private EditText phoneNum;
    String serial;
    private TextView text1;
    private TextView text2;
    private TextView textw;
    public static final int[] ERROR_STRING = {R.string.register_error_server_error, R.string.register_error_invalid_platform, R.string.register_error_invalid_series, R.string.register_error_invalid_device, R.string.register_error_series_used, R.string.register_error_device_used};
    public static char[] chars = {'a', 'b', 'c', 'd', 'e', 'f', 'h', 'j', 'k', 'm', 'n', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y'};

    private void showAlertdialog() {
        new WIFI_Listener(this).showAlertDialog();
    }

    @Override // android.app.Activity
    protected void onStart() {
        super.onStart();
        if (network()) {
            return;
        }
        showAlertdialog();
    }

    public String replaceBlank(String str) {
        return str != null ? Pattern.compile("\t|\r|\n|\\s*").matcher(str).replaceAll("") : "";
    }

    @Override // android.app.Activity, android.view.KeyEvent.Callback
    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (i == 4) {
            return true;
        }
        return super.onKeyDown(i, keyEvent);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean network() {
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity");
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        connectivityManager.getNetworkInfo(0);
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

    @Override // android.app.Activity
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        Log.e("dimen:", getResources().getDimension(R.dimen.x480) + "");
        Log.e("dimen:", getResources().getDimension(R.dimen.y768) + "");
        requestWindowFeature(1);
        setContentView(R.layout.activity_main);
        Display defaultDisplay = getWindowManager().getDefaultDisplay();
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        double width = defaultDisplay.getWidth();
        Double.isNaN(width);
        attributes.width = (int) (width * 0.7d);
        double height = defaultDisplay.getHeight();
        Double.isNaN(height);
        attributes.height = (int) (height * 0.7d);
        getWindow().setAttributes(attributes);
        this.mInputSeries = (EditText) findViewById(R.id.register_series);
        this.phoneNum = (EditText) findViewById(R.id.register_phone);
        this.mRegister = (Button) findViewById(R.id.register_go);
        this.ll_phone = (LinearLayout) findViewById(R.id.ll_phone);
        this.is = false;
        this.mRegister.setOnClickListener(new AnonymousClass1());
    }

    /* renamed from: com.jxw.engine.platsign.MainActivity$1  reason: invalid class name */
    /* loaded from: classes.dex */
    class AnonymousClass1 implements View.OnClickListener {
        AnonymousClass1() {
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            String obj = MainActivity.this.phoneNum.getText().toString();
            if (obj != null && obj.length() == 0) {
                Toast.makeText(MainActivity.this, "请输入手机号码", 0).show();
            } else if (obj == null || obj.length() == 11 || MainActivity.ispsd(obj)) {
                if (MainActivity.this.network()) {
                    MainActivity.this.mRegister.setEnabled(false);
                    final String obj2 = MainActivity.this.mInputSeries.getText().toString();
                    MainActivity.this.serial = MyApp.getInstance().getUserInfo();
                    if ("".equals(MainActivity.this.serial)) {
                        MainActivity mainActivity = MainActivity.this;
                        MyApp.getInstance();
                        mainActivity.serial = MyApp.getRKSerial();
                    }
                    MainActivity mainActivity2 = MainActivity.this;
                    MyApp.getInstance();
                    mainActivity2.mcpuid = MyApp.getCPUSerial();
                    Log.e(MainActivity.TAG, "serial=:" + MainActivity.this.serial + ",cpuid=" + MainActivity.this.mcpuid);
                    if (MainActivity.this.mcpuid != null && MainActivity.this.mcpuid.contains("000000000000000")) {
                        MainActivity.this.mcpuid = null;
                    }
                    if (TextUtils.isEmpty(MainActivity.this.serial) && TextUtils.isEmpty(MainActivity.this.mcpuid) && (obj2 == null || obj2.isEmpty())) {
                        MainActivity mainActivity3 = MainActivity.this;
                        mainActivity3.showDialog(mainActivity3.getString(R.string.invalid_series));
                        MainActivity.this.mRegister.setEnabled(true);
                        return;
                    }
                    new Thread(new Runnable() { // from class: com.jxw.engine.platsign.MainActivity.1.1
                        @Override // java.lang.Runnable
                        public void run() {
                            boolean z;
                            String str = null;
                            for (int i = 0; i < 5; i++) {
                                try {
                                    str = MyApp.getInstance().macAddress();
                                } catch (SocketException e) {
                                    e.printStackTrace();
                                }
                                if (str != null) {
                                    break;
                                }
                            }
                            String str2 = str;
                            if (!MainActivity.this.is && TextUtils.isEmpty(obj2)) {
                                MainActivity.this.mInputSeries.post(new Runnable() { // from class: com.jxw.engine.platsign.MainActivity.1.1.2
                                    @Override // java.lang.Runnable
                                    public void run() {
                                        MainActivity mainActivity4 = MainActivity.this;
                                        mainActivity4.showDialog(MainActivity.this.getString(R.string.register_fail) + MainActivity.this.getString(R.string.invalid_series));
                                        MainActivity.this.mRegister.setEnabled(true);
                                    }
                                });
                                return;
                            }
                            Log.e("is:", MainActivity.this.is + "====" + obj2);
                            final String obj3 = MainActivity.this.phoneNum.getText().toString();
                            try {
                                Long.parseLong(obj2);
                                z = true;
                            } catch (Exception e2) {
                                e2.printStackTrace();
                                z = false;
                            }
                            String str3 = obj2;
                            try {
                                if (!z) {
                                    char c = 0;
                                    for (int i2 = 0; i2 < obj2.length() - 1; i2++) {
                                        c = (char) (c ^ obj2.charAt(i2));
                                    }
                                    if (obj2.charAt(obj2.length() - 1) == MainActivity.chars[c % MainActivity.chars.length]) {
                                        str3 = MyApp.getInstance().getDeviceSerial();
                                    }
                                } else if (str3.length() == 10) {
                                    int charAt = obj2.charAt(8) - '0';
                                    int charAt2 = obj2.charAt(1) - '0';
                                    int charAt3 = obj2.charAt(2) - '0';
                                    int charAt4 = obj2.charAt(3) - '0';
                                    if ((obj2.charAt(0) - '0') * 2 == charAt && Math.abs(charAt2 - charAt3) == charAt4) {
                                        str3 = MyApp.getInstance().getDeviceSerial();
                                        if ("unknown".equals(str3) || TextUtils.isEmpty(str3)) {
                                            str3 = MyApp.getInstance().getDeviceSerialx();
                                        }
                                        if ("unknown".equals(str3)) {
                                            str3 = MyApp.getInstance().get_JzyhSN();
                                        } else {
                                            TextUtils.isEmpty(str3);
                                        }
                                        Log.e(MainActivity.TAG, "假码注册获取sn号=" + str3);
                                    }
                                }
                            } catch (Exception unused) {
                            }
                            final String register = MyApp.getInstance().register(1, "A89S", str2, str3, MainActivity.this.serial, obj3, MainActivity.this.mcpuid);
                            MainActivity.this.mInputSeries.post(new Runnable() { // from class: com.jxw.engine.platsign.MainActivity.1.1.1
                                @Override // java.lang.Runnable
                                public void run() {
                                    Log.e(MainActivity.CERTIFICATION, register + "");
                                    MainActivity.this.mRegister.setEnabled(true);
                                    String[] parseResult = MyApp.getInstance().parseResult(register);
                                    if (parseResult != null) {
                                        try {
                                            int parseInt = Integer.parseInt(parseResult[0], 10);
                                            if (parseInt >= 200 && parseInt <= 201) {
                                                if (MyApp.getInstance().saveCertification(parseResult[1])) {
                                                    MainActivity.this.sendBroadcast(new Intent("com.zzj.regist_success"));
                                                    MainActivity.this.showDialog();
                                                } else {
                                                    MainActivity mainActivity4 = MainActivity.this;
                                                    mainActivity4.showDialog(MainActivity.this.getString(R.string.register_fail) + MainActivity.this.getString(R.string.save_cert_fail));
                                                }
                                            } else {
                                                MainActivity mainActivity5 = MainActivity.this;
                                                mainActivity5.showDialog(MainActivity.this.getString(R.string.register_fail) + parseResult[0] + "(" + MainActivity.this.getErrorString(parseResult[0]) + ")");
                                            }
                                            return;
                                        } catch (NumberFormatException e3) {
                                            e3.printStackTrace();
                                            return;
                                        }
                                    }
                                    MainActivity mainActivity6 = MainActivity.this;
                                    mainActivity6.showDialog(MainActivity.this.getString(R.string.register_fail) + MainActivity.this.getString(R.string.network_error));
                                }
                            });
                        }
                    }).start();
                    return;
                }
                MainActivity.this.startActivity(new Intent("android.settings.WIFI_SETTINGS"));
            } else {
                Toast.makeText(MainActivity.this, "请输入正确的手机号码", 0).show();
            }
        }
    }

    private void initText2(String str) {
        SpannableString spannableString = new SpannableString(str);
        spannableString.setSpan(new TextAppearanceSpan(this, R.style.tv_style1), 0, 5, 33);
        spannableString.setSpan(new TextAppearanceSpan(this, R.style.tv_style2), 5, str.length(), 33);
        this.text2.setText(spannableString, TextView.BufferType.SPANNABLE);
    }

    private void initText1(String str) {
        SpannableString spannableString = new SpannableString(str);
        spannableString.setSpan(new TextAppearanceSpan(this, R.style.tv_style3), 0, 15, 33);
        spannableString.setSpan(new TextAppearanceSpan(this, R.style.tv_style4), 15, str.length(), 33);
        this.textw.setText(spannableString, TextView.BufferType.SPANNABLE);
    }

    private void initText(String str) {
        SpannableString spannableString = new SpannableString(str);
        spannableString.setSpan(new TextAppearanceSpan(this, R.style.tv_style1), 0, 22, 33);
        spannableString.setSpan(new TextAppearanceSpan(this, R.style.tv_style2), 22, str.length(), 33);
        this.text1.setText(spannableString, TextView.BufferType.SPANNABLE);
    }

    public static boolean ispsd(String str) {
        return Pattern.compile("^[0-9]*$").matcher(str).matches();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public String getErrorString(String str) {
        int parseInt = Integer.parseInt(str);
        if (parseInt == 901) {
            return getString(R.string.register_error_invalid);
        }
        int[] iArr = ERROR_STRING;
        return getString(iArr[(parseInt - 100) % iArr.length]);
    }

    @Override // android.app.Activity
    protected void onResume() {
        super.onResume();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void showDialog(String str) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(str);
        builder.setTitle("提示");
        builder.create().show();
    }

    @Override // android.app.Activity
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        super.onRequestPermissionsResult(i, strArr, iArr);
    }

    /* renamed from: com.jxw.engine.platsign.MainActivity$2  reason: invalid class name */
    /* loaded from: classes.dex */
    class AnonymousClass2 implements View.OnClickListener {
        AnonymousClass2() {
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            MainActivity.this.finish();
        }
    }

    /* renamed from: com.jxw.engine.platsign.MainActivity$3  reason: invalid class name */
    /* loaded from: classes.dex */
    class AnonymousClass3 implements View.OnClickListener {
        AnonymousClass3() {
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            MainActivity.this.finish();
        }
    }

    /* renamed from: com.jxw.engine.platsign.MainActivity$4  reason: invalid class name */
    /* loaded from: classes.dex */
    class AnonymousClass4 implements View.OnClickListener {
        AnonymousClass4() {
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            MainActivity.this.finish();
        }
    }

    /* renamed from: com.jxw.engine.platsign.MainActivity$5  reason: invalid class name */
    /* loaded from: classes.dex */
    class AnonymousClass5 implements View.OnClickListener {
        AnonymousClass5() {
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            MainActivity.this.finish();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void showDialog() {
        findViewById(R.id.registered).setVisibility(0);
        findViewById(R.id.registered).setOnClickListener(new View.OnClickListener() { // from class: com.jxw.engine.platsign.MainActivity.6
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                MainActivity.this.finish();
            }
        });
    }

    public String getDeviceSerial() {
        String str = SystemPropertiesProxy.get(this, "ro.serialno");
        if (TextUtils.isEmpty(str)) {
            if (Build.VERSION.SDK_INT >= 29) {
                str = Build.getSerial();
            } else {
                str = Build.SERIAL;
            }
        }
        return (TextUtils.isEmpty(str) || str.length() < 8) ? SystemPropertiesProxy.get(this, "persist.sys.serialno") : str;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendMsg(String str) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("mobile", str);
            jSONObject.put("apikey", "N34556a187");
            jSONObject.put("secret", "34556cf3b4c1641a");
            jSONObject.put("template_id", "138945");
            jSONObject.put("sign_id", "116436");
            new OkHttpClient().newCall(new Request.Builder().url("https://api.4321.sh/sms/template").post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jSONObject.toString())).build()).enqueue(new Callback() { // from class: com.jxw.engine.platsign.MainActivity.7
                @Override // okhttp3.Callback
                public void onFailure(Call call, IOException iOException) {
                    Log.d("zsj", "sendPost onFailure=" + iOException.getMessage());
                }

                @Override // okhttp3.Callback
                public void onResponse(Call call, Response response) {
                    try {
                        new JSONObject(response.body().string());
                    } catch (Exception e) {
                        e.getMessage();
                    }
                }
            });
        } catch (Exception unused) {
        }
    }
}
